{include file="public/head"}
<style>
    .x-body {
        min-width: 1100px;
    }

    body {
        overflow-x: scroll;
    }
</style>
<body>
<div class="x-body">
    <div class="lotus-nav">
        <input type="hidden" id="company_id" name="company_id" value="{$Think.get.company_id}">
        <button class="layui-btn layui-btn-sm" onclick="x_admin_show('添加店铺','storeAdd.html?company_id={$Think.get.company_id}')">
            <i class="layui-icon layui-icon-add-circle"></i>新建
        </button>
        {if empty($Think.get.company_id)}
        {if count($store)>0}
        <button class="layui-btn layui-btn-sm layui-btn-normal" onclick="x_admin_show('店铺参数','batch.html')">
            批量修改店铺参数
        </button>
        {/if}

        <button class="layui-btn layui-btn-sm layui-btn-danger" onclick="delAll()"><i class="layui-icon"></i>批量删除
        </button>
        {/if}
        <span class="x-right">共有数据:<i class="i_count">{$store->total()}</i>条
        <button onclick="javascript:location.reload()" class="layui-btn-default ">
            <i class="layui-icon layui-icon-refresh"></i>
        </button>
        </span>
    </div>


    <table class="layui-table">
        <thead>
        <tr>
            <th style="width: 75px;text-align: center">
                <div class="header layui-form-checkbox" lay-skin="primary"><i class="layui-icon">&#xe605;</i></div>
            </th>
            <th style="min-width: 70px;">店铺名称</th>
            <th>店铺域名</th>
            <th style="min-width: 70px;text-align:center">所属国家</th>
            <th style="min-width: 130px;text-align:center"><a
                    href="http://docs.developer.amazonservices.com/zh_CN/dev_guide/DG_Endpoints.html" target="_blank"
                    style="color: #01AAED;text-decoration:underline;cursor:hand">亚马逊MarketplaceId</a></th>
            <th style="width: 40px;text-align:center">状态</th>
            <th style="width: 120px;text-align:center">创建时间</th>
            <th style="width: 160px;text-align:center">操作</th>
        </thead>
        <tbody>

        {volist name="store" id="vo"}
        <tr>
            <td style="text-align:center">
                <div class="layui-form-checkbox" lay-skin="primary" data-id='{$vo.id}'><i
                        class="layui-icon">&#xe605;</i></div>
            </td>
            <td>{$vo.name}</td>
            <td>{$vo.org}</td>
            <td style="text-align:center">{$vo.nation}</td>
            <td style="text-align:center">{$vo.marketplace}</td>
            <td style="text-align:center">
                {if $vo['status'] == 1}
                <b style="color: green">启用</b>
                {else/}
                <b style="color: red">禁用</b>
                {/if}
            </td>
            <td style="text-align:center">{$vo['timestamp']|date="Y-m-d H:i",###}</td>
            <td style="text-align:center">
                <button class="layui-btn layui-btn-xs"
                        onclick="x_admin_show('编辑','storeEdit.html?id={$vo.id}&company_id={$Think.get.company_id}')">编辑
                </button>
                {if empty($Think.get.company_id)}
                <button class="layui-btn layui-btn-xs layui-btn-normal"
                        onclick="m_admin_show('分配用户','storeUser.html?id={$vo.id}','50%')">分配用户
                </button>
                <button onclick="del(this,'{$vo.id}')" class="layui-btn layui-btn-xs layui-btn-danger">
                    删除
                </button>
                {/if}
            </td>
        </tr>
        {/volist}

        </tbody>
    </table>
    <div class="page">
        <div>
            {$store->render()}
        </div>
    </div>
</div>
</body>
{include file="public/foot"}
<script>

    //删除所有
    function delAll() {
        var data = tableCheck.getData();
        if (data.length == 0) {
            layer.msg("请选择需要删除的店铺");
            return false;
        }
        layer.confirm('确认要全部删除吗？', function (index) {
            //捉到所有被选中的，发异步进行删除
            $.post("{:url('admin/amazonstore/storeDel')}", {id: data}, function (data, textStatus, xhr) {
                if (data.code == 1) {
                    layer.msg(data.msg, {icon: 1, time: 1000}, function () {
                        $(".layui-form-checked").not('.header').parents('tr').remove();
                    });
                } else {
                    layer.msg(data.msg, {icon: 2, time: 1000});
                }

            });
        });
    }

    function del(obj, id) {
        var count = $(".i_count")[0].innerText;
        layer.confirm('确认要删除吗？', function (index) {
            //捉到所有被选中的，发异步进行删除
            $.post("{:url('admin/amazonstore/storeDel')}", {id: id}, function (data, textStatus, xhr) {
                if (data.code == 1) {
                    layer.msg(data.msg, {icon: 1, time: 1000}, function () {
                        $(obj).parents('tr').remove();
                        $(".i_count").html(count - 1);
                    });
                } else {
                    layer.msg(data.msg, {icon: 2, time: 1000});
                }

            });
        });
    }
</script>
